mrzhssss
2022-01-17 0dd23ce00979f8aa836b19e3c565094665d6fa47
src/main/java/zy/cloud/wms/manager/controller/ItemController.java
@@ -10,11 +10,18 @@
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zy.cloud.wms.common.web.BaseController;
import zy.cloud.wms.manager.entity.Cstmr;
import zy.cloud.wms.manager.entity.Item;
import zy.cloud.wms.manager.entity.ProjectPlan;
import zy.cloud.wms.manager.entity.ProjectType;
import zy.cloud.wms.manager.service.CstmrService;
import zy.cloud.wms.manager.service.ItemService;
import zy.cloud.wms.manager.service.ProjectPlanService;
import zy.cloud.wms.manager.service.ProjectTypeService;
import java.util.*;
@@ -23,6 +30,8 @@
    @Autowired
    private ItemService itemService;
    @Autowired
    private ProjectPlanService planService;
    @RequestMapping(value = "/item/{id}/auth")
    @ManagerAuth
@@ -38,9 +47,14 @@
                  @RequestParam(required = false)String orderByType,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<Item> wrapper = new EntityWrapper<>();
        HashSet<String> excludeField = new HashSet<>();
//        allLike(Item.class,excludeField,wrapper, (String) param.get("id"));
        excludeTrash(param);
        convert(param, wrapper);
        hostEq(wrapper);
//        wrapper.orderBy("status",true);
        wrapper.orderBy("id",false);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(itemService.selectPage(new Page<>(curr, limit), wrapper));
    }
@@ -62,42 +76,73 @@
    @ManagerAuth
    public R add(Item item) {
        if (Cools.isEmpty(item)) {
            return R.error("参数为空,请联系管理员");
        }
        if (!item.getType().equals("1")) {
            throw new CoolException("目前仅支持集成项目");
        }
        Item name = itemService.selectOne(new EntityWrapper<Item>()
                .eq("name", item.getName()));
        if (!Cools.isEmpty(name)) {
            throw new CoolException("不可有重复项目名");
        }
        if (item.getRealMonth() < 0){
            throw new CoolException("实施周期不可为负数");
        }
        item.setHostId(getHostId());
        item.setCreateBy(getUserId());
        item.setCreateTime(new Date());
        item.setStatus(1);
        item.setUpdateBy(getUserId());
        item.setUpdateTime(new Date());
        itemService.insert(item);
        itemService.insertAll(item);
        return R.ok();
    }
   @RequestMapping(value = "/item/update/auth")
   @ManagerAuth
    public R update(Item item){
        if (Cools.isEmpty(item) || null==item.getUuid()){
            return R.error();
        if (Cools.isEmpty(item)) {
            return R.error("参数为空,请联系管理员");
        }
        if (!item.getType().equals("1")) {
            throw new CoolException("目前仅支持集成项目");
        }
        if (item.getRealMonth() < 0){
            throw new CoolException("实施周期不可为负数");
        }
        item.setUpdateBy(getUserId());
        item.setUpdateTime(new Date());
        itemService.updateById(item);
        itemService.update(item,new EntityWrapper<Item>()
                .eq("id",item.getId()));
//        itemService.updateById(item);
        return R.ok();
    }
    @RequestMapping(value = "/item/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam("ids[]") String param){
//        if (param != null){
//            itemService.delete(new EntityWrapper<Item>()
//                    .eq("id",param));
//            planService.delete(new EntityWrapper<ProjectPlan>()
//                    .eq("item_id",param));
//        }
        if (param != null){
            itemService.delete(new EntityWrapper<Item>()
                    .eq("id",param));
            String[] split = param.split(",");
            for (String s : split) {
                Item item = itemService.selectOne(new EntityWrapper<Item>()
                        .eq("id", s));
                item.setStatus(2);
                itemService.update(item,new EntityWrapper<Item>()
                        .eq("id",item.getId()));
            }
        }
//        List<Item> list = JSONArray.parseArray(param, Item.class);
//        if (Cools.isEmpty(list)){
//            return R.error();
//        }
//        for (Item entity : list){
//            itemService.delete(new EntityWrapper<>(entity));
//        }
        return R.ok();
    }