|  |  | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSONArray; | 
 |  |  | import com.alibaba.fastjson.JSONObject; | 
 |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
 |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
 |  |  | import com.baomidou.mybatisplus.plugins.Page; | 
 |  |  | import com.core.common.DateUtils; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import @{COMPANYNAME}.entity.@{ENTITYNAME}; | 
 |  |  | import @{COMPANYNAME}.service.@{ENTITYNAME}Service; | 
 |  |  | import com.core.annotations.ManagerAuth; | 
 |  |  | import com.core.common.BaseRes; | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.core.common.R; | 
 |  |  | import com.core.domain.KeyValueVo; | 
 |  |  | import @{SYSTEMPACKAGE}.common.web.BaseController; | 
 |  |  | import com.zy.asrs.framework.annotations.ManagerAuth; | 
 |  |  | import com.zy.asrs.framework.common.Cools; | 
 |  |  | import com.zy.asrs.framework.common.R; | 
 |  |  | import com.zy.asrs.framework.domain.KeyValueVo; | 
 |  |  | import com.zy.asrs.framework.common.DateUtils; | 
 |  |  | import com.zy.asrs.common.web.BaseController; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  |  | 
 |  |  | 
 |  |  |     @RequestMapping(value = "/@{SIMPLEENTITYNAME}/{id}/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R get(@PathVariable("id") String id) { | 
 |  |  |         return R.ok(@{SIMPLEENTITYNAME}Service.selectById(String.valueOf(id))); | 
 |  |  |         return R.ok(@{SIMPLEENTITYNAME}Service.getById(String.valueOf(id))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/@{SIMPLEENTITYNAME}/page/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R page(@RequestParam(defaultValue = "1")Integer curr, | 
 |  |  |                   @RequestParam(defaultValue = "10")Integer limit, | 
 |  |  |                   @RequestParam(required = false)String orderByField, | 
 |  |  |                   @RequestParam(required = false)String orderByType, | 
 |  |  |                   @RequestParam(required = false)String condition, | 
 |  |  |                   @RequestParam Map<String, Object> param){ | 
 |  |  |         EntityWrapper<@{ENTITYNAME}> wrapper = new EntityWrapper<>(); | 
 |  |  |         excludeTrash(param); | 
 |  |  |         convert(param, wrapper); | 
 |  |  |         allLike(@{ENTITYNAME}.class, param.keySet(), wrapper, condition); | 
 |  |  |         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
 |  |  |         return R.ok(@{SIMPLEENTITYNAME}Service.selectPage(new Page<>(curr, limit), wrapper)); | 
 |  |  |     public R page(@RequestParam(defaultValue = "1") Integer curr, | 
 |  |  |                   @RequestParam(defaultValue = "10") Integer limit, | 
 |  |  |                   @RequestParam(required = false) String condition, | 
 |  |  |                   @RequestParam(required = false) String timeRange, | 
 |  |  |                   @RequestParam Map<String, Object> param) { | 
 |  |  |         LambdaQueryWrapper<@{ENTITYNAME}> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(@{ENTITYNAME}::get@{MAJORCOLUMN0}, condition); | 
 |  |  |         } | 
 |  |  |         if (!Cools.isEmpty(timeRange)) { | 
 |  |  |             String[] range = timeRange.split(RANGE_TIME_LINK); | 
 |  |  |             wrapper.ge(@{ENTITYNAME}::getCreateTime, DateUtils.convert(range[0])); | 
 |  |  |             wrapper.le(@{ENTITYNAME}::getCreateTime, DateUtils.convert(range[1])); | 
 |  |  |         } | 
 |  |  |         return R.ok(@{SIMPLEENTITYNAME}Service.page(new Page<>(curr, limit), wrapper)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
 |  |  |         for (Map.Entry<String, Object> entry : map.entrySet()){ | 
 |  |  |             String val = String.valueOf(entry.getValue()); | 
 |  |  |             if (val.contains(RANGE_TIME_LINK)){ | 
 |  |  |                 String[] dates = val.split(RANGE_TIME_LINK); | 
 |  |  |                 wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
 |  |  |                 wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
 |  |  |             } else { | 
 |  |  |                 wrapper.like(entry.getKey(), val); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/@{SIMPLEENTITYNAME}/add/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R add(@{ENTITYNAME} @{SIMPLEENTITYNAME}) { | 
 |  |  |         @{SIMPLEENTITYNAME}Service.insert(@{SIMPLEENTITYNAME}); | 
 |  |  |         @{SIMPLEENTITYNAME}Service.save(@{SIMPLEENTITYNAME}); | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
 |  |  |          for (Long id : ids){ | 
 |  |  |             @{SIMPLEENTITYNAME}Service.deleteById(id); | 
 |  |  |             @{SIMPLEENTITYNAME}Service.removeById(id); | 
 |  |  |         } | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/@{SIMPLEENTITYNAME}/export/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R export(@RequestBody JSONObject param){ | 
 |  |  |         EntityWrapper<@{ENTITYNAME}> wrapper = new EntityWrapper<>(); | 
 |  |  |         List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
 |  |  |         Map<String, Object> map = excludeTrash(param.getJSONObject("@{SIMPLEENTITYNAME}")); | 
 |  |  |         convert(map, wrapper); | 
 |  |  |         List<@{ENTITYNAME}> list = @{SIMPLEENTITYNAME}Service.selectList(wrapper); | 
 |  |  |         return R.ok(exportSupport(list, fields)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/@{SIMPLEENTITYNAME}Query/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R query(String condition) { | 
 |  |  |         EntityWrapper<@{ENTITYNAME}> wrapper = new EntityWrapper<>(); | 
 |  |  |         wrapper.like("@{MAJORCOLUMN}", condition); | 
 |  |  |         Page<@{ENTITYNAME}> page = @{SIMPLEENTITYNAME}Service.selectPage(new Page<>(0, 10), wrapper); | 
 |  |  |         LambdaQueryWrapper<@{ENTITYNAME}> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         wrapper.like(@{ENTITYNAME}::get@{MAJORCOLUMN0}, condition); | 
 |  |  |         Page<@{ENTITYNAME}> page = @{SIMPLEENTITYNAME}Service.page(new Page<>(0, 10), wrapper); | 
 |  |  |         List<Map<String, Object>> result = new ArrayList<>(); | 
 |  |  |         for (@{ENTITYNAME} @{SIMPLEENTITYNAME} : page.getRecords()){ | 
 |  |  |             Map<String, Object> map = new HashMap<>(); | 
 |  |  | 
 |  |  |         return R.ok(result); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping(value = "/@{SIMPLEENTITYNAME}/check/column/auth") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R query(@RequestBody JSONObject param) { | 
 |  |  |         Wrapper<@{ENTITYNAME}> wrapper = new EntityWrapper<@{ENTITYNAME}>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
 |  |  |         if (null != @{SIMPLEENTITYNAME}Service.selectOne(wrapper)){ | 
 |  |  |             return R.parse(BaseRes.REPEAT).add(getComment(@{ENTITYNAME}.class, String.valueOf(param.get("key")))); | 
 |  |  |         } | 
 |  |  |         return R.ok(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @RequestMapping("/@{SIMPLEENTITYNAME}/all/get/kv") | 
 |  |  |     @ManagerAuth | 
 |  |  |     public R getDataKV(@RequestParam(required = false) String condition) { | 
 |  |  |         List<KeyValueVo> vos = new ArrayList<>(); | 
 |  |  |         Wrapper<@{ENTITYNAME}> wrapper = new EntityWrapper<@{ENTITYNAME}>().andNew().like("@{MAJORCOLUMN}", condition).orderBy("create_time", false); | 
 |  |  |         @{SIMPLEENTITYNAME}Service.selectPage(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.get@{MAJORCOLUMN_UP}()), item.get@{PRIMARYKEYCOLUMN}()))); | 
 |  |  |         LambdaQueryWrapper<@{ENTITYNAME}> wrapper = new LambdaQueryWrapper<>(); | 
 |  |  |         if (!Cools.isEmpty(condition)) { | 
 |  |  |             wrapper.like(@{ENTITYNAME}::get@{MAJORCOLUMN0}, condition); | 
 |  |  |         } | 
 |  |  |         @{SIMPLEENTITYNAME}Service.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.get@{MAJORCOLUMN0}()), item.get@{PRIMARYKEYCOLUMN}()))); | 
 |  |  |         return R.ok().add(vos); | 
 |  |  |     } | 
 |  |  |  |