Quellcode durchsuchen

服务包代码

suqinyi vor 1 Jahr
Ursprung
Commit
f2e2e3325a

+ 10 - 1
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/qvo/ParamQvo.java

@ -10,9 +10,10 @@ public class ParamQvo {
    private String leasedCode;//租户
    private String orgCode;//机构code
    private String searchKey;//机构code
    private String searchKey;//关键字
    private String status;//状态
    private String name;//名称
    private String jsonStr;
@ -25,6 +26,14 @@ public class ParamQvo {
        return id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setId(String id) {
        this.id = id;
    }

+ 98 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/servicePackage/ServicePackageSubItemEndpoint.java

@ -0,0 +1,98 @@
package com.yihu.jw.base.endpoint.servicePackage;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.service.servicePackage.ServicePackageISubtemService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.entity.base.servicePackage.ServicePackageItemDO;
import com.yihu.jw.entity.base.servicePackage.ServicePackageSubItemDO;
import com.yihu.jw.restmodel.qvo.ParamQvo;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2021/2/23.
 */
@RestController
@RequestMapping(value = "servicePackageSubItem", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(value = "服务子项管理", description = "服务子项管理", tags = {"wlyy基础服务 - 服务项管理服务接口"})
public class ServicePackageSubItemEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private ServicePackageISubtemService subItemService;
    /**
     * 查询所有服务子项
     */
    @GetMapping(value = "getItemList")
    @ApiOperation(value = "查询所有服务项")
    public PageEnvelop<Map<String, Object>> getSubItemList(
            @ApiParam(name = "jsonStr", value = "Json数据", required = true) @RequestParam String jsonStr
    ) throws Exception {
        ParamQvo qvo = JSON.parseObject(jsonStr, ParamQvo.class);
        Map<String, Object> map = subItemService.getSubItemList(qvo);
        List<Map<String, Object>> list = (List<Map<String, Object>>) map.get("list");
        Integer count = (Integer) map.get("count");
        return success(list, count, qvo.getPage(), qvo.getPageSize());
    }
    @PostMapping(value = "createSubItem")
    @ApiOperation(value = "创建服务子项")
    public Envelop createSubItem(
            @ApiParam(name = "jsonStr", value = "Json数据", required = true) @RequestParam String jsonStr) throws Exception {
        ServicePackageSubItemDO subItemDO = toEntity(jsonStr, ServicePackageSubItemDO.class);
        JSONObject result = subItemService.createSubItem(subItemDO);
        if (StringUtils.endsWithIgnoreCase(ConstantUtils.FAIL, result.getString("response"))) {
            return failed(result.getString("msg"));
        }
        return success(result.get("msg"));
    }
    /**
     * 改变状态
     */
    @PostMapping(value = "changeState")
    @ApiOperation(value = "改变状态")
    public ObjEnvelop changeState(
            @ApiParam(name = "jsonStr", value = "jsonStr", required = true) @RequestParam String jsonStr) throws Exception {
        try {
            ParamQvo qvo = JSON.parseObject(jsonStr, ParamQvo.class);
            if (org.apache.commons.lang3.StringUtils.isBlank(qvo.getId())) {
                return failed("ID不能为空", ObjEnvelop.class);
            }
            System.out.println("参数:" + JSON.toJSONString(qvo));
            ServicePackageSubItemDO entity = subItemService.changeState(qvo);
            return success(entity);
        } catch (Exception e) {
            e.printStackTrace();
            return failedObjEnvelopException(e);
        }
    }
    @PostMapping(value = "deleteById")
    @ApiOperation(value = "删除")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id串,中间用,分隔", required = true) @RequestParam(value = "ids") String ids) throws Exception {
        subItemService.deleteById(ids);
        return success("删除成功");
    }
}

+ 86 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/servicePackage/ServicePackageISubtemService.java

@ -0,0 +1,86 @@
package com.yihu.jw.base.service.servicePackage;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.servicePackage.ServicePackageSubItemDao;
import com.yihu.jw.entity.base.servicePackage.ServicePackageItemDO;
import com.yihu.jw.entity.base.servicePackage.ServicePackageSubItemDO;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.restmodel.qvo.ParamQvo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * Created by yeshijie on 2021/2/23.
 */
@Service
public class ServicePackageISubtemService extends BaseJpaService<ServicePackageSubItemDO, ServicePackageSubItemDao> {
    @Autowired
    private ServicePackageSubItemDao subItemDao;
    public Map<String, Object> getSubItemList(ParamQvo qvo) {
        String detailSql = "select * ";
        String countSql = " select count(1) ";
        String pageSql = "";
        String sql = " FROM base_service_package_sub_item WHERE 1=1  ";
        if (StringUtils.isNotBlank(qvo.getLeasedCode())) {
            sql += "AND leased_code = '" + qvo.getLeasedCode() + "'";
        }
        if (StringUtils.isNotBlank(qvo.getOrgCode())) {
            sql += "AND org_code = '" + qvo.getOrgCode() + "'";
        }
        if (StringUtils.isNotBlank(qvo.getStatus())) {
            sql += "AND `status` = '" + qvo.getStatus() + "'";
        }
        if (StringUtils.isNotBlank(qvo.getName())) {
            sql += "AND `name` like '%" + qvo.getStatus() + "%'";
        }
        if (StringUtils.isNotBlank(qvo.getPageIf())) {
            sql += " limit " + (qvo.getPage() - 1) * qvo.getPageSize() + "," + qvo.getPageSize();
        }
        detailSql += sql + pageSql;
        countSql += sql;
        Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(detailSql);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("list", list);
        return map;
    }
    public JSONObject createSubItem(ServicePackageSubItemDO subItemDO) {
        ServicePackageSubItemDO entity = subItemDao.save(subItemDO);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data",entity);
        jsonObject.put("msg","操作成功");
        return jsonObject;
    }
    public ServicePackageSubItemDO changeState(ParamQvo qvo) throws Exception {
        ServicePackageSubItemDO entity = subItemDao.findById(qvo.getId()).orElse(null);
        if (entity!=null){
            entity.setStatus(qvo.getStatus());
            ServicePackageSubItemDO save = subItemDao.save(entity);
            return save;
        }else {
            throw new  Exception("没有找到数据");
        }
    }
    public void deleteById(String ids) {
        String collect = Arrays.stream(ids.split(",")).map(s -> "'" + s + "'").collect(Collectors.joining(",", "(", ")"));
        String delSql = "DELETE FROM base_service_package_sub_item WHERE id IN ";
        delSql += collect;
        jdbcTemplate.execute(delSql);
    }
}