package cn.com.goldenwater.dcproj.controller.general; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.constValue.CommonLabel; import cn.com.goldenwater.dcproj.param.TypeParam; import cn.com.goldenwater.dcproj.service.BisInspKeyRegisterService; import cn.com.goldenwater.dcproj.service.BisInspObjStrategy; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.service.impl.system.BisInspObjFactory; import cn.com.goldenwater.dcproj.target.Authority; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.DateUtils; import cn.com.goldenwater.target.CheckException; import cn.com.goldenwater.util.common.SqlUtils; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Optional; @Api(value = "督查类型列表管理", tags = "list督查对象管理") @RestController @RequestMapping("/dc/insp/rsvrRgstr/list") public class RgstrController extends BaseController { @Value("${pagehelper.helperDialect}") private String sqlDialect ; @Autowired private BisInspObjFactory factory; @Autowired private BisInspKeyRegisterService bisInspKeyRegisterService; @Autowired private OlBisInspOrgService olBisInspOrgService; @ApiOperation(value = "根据记录人员id获取需要督查的172工程列表树形结构") @RequestMapping(value = "/tree", method = RequestMethod.POST) public BaseResponse tree(@RequestBody TypeParam typeParam) { typeParam.setPresId(getCurrentPersId()); typeParam.setOrgId(getCurrentOrgId()); typeParam.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); typeParam.setNowTime(DateUtils.getToday("yyyy-MM-dd")); typeParam.setInIdsSql(SqlUtils.getinIdsSql(typeParam.getPresId(), typeParam.getProvince())); if (!StringUtils.isBlank(typeParam.getAdCodes())) { typeParam.setAdCodes(AdLevelUtil.getListAddvcd(typeParam.getAdCodes())); } BisInspEnum bisInspEnum = BisInspEnum.getEnumByKey(typeParam.getType()); Optional.ofNullable(bisInspEnum).orElseThrow(() -> new CheckException("缺少督查项的KEY")); switch (bisInspEnum) { case EMPWTRUN: typeParam.setpType(BisInspEnum.EMPWTRUN.getValue()); return buildSuccessResponse(bisInspKeyRegisterService.treeEmpwtrun(typeParam)); case EMPWT: typeParam.setpType(BisInspEnum.EMPWT.getValue()); return buildSuccessResponse(bisInspKeyRegisterService.treeEmpwt(typeParam)); default: throw new CheckException("只能选择水利工程建设、水利工程运行!"); } } @Authority @ApiOperation(value = "根据记录人员id获取需要督查水库(type=rsvr),农水(type=vill),水毁(type=rect)," + "172工程列表(type=empwt),地下水(type=grw),水闸(type=waga),稽察项目(type=pawp)persId人员id,plnaId批次id") @RequestMapping(value = "/type", method = RequestMethod.POST) public Object listType(@RequestBody TypeParam typeParam, HttpServletResponse response, HttpServletRequest request) { if (StringUtils.isBlank(typeParam.getpType()) && StringUtils.isBlank(typeParam.getType())) { throw new CheckException("缺少参数,type 或 pType"); } typeParam.setPresId(getCurrentPersId()); String adPr = AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())); if (StringUtils.isBlank(typeParam.getAdCode())) { typeParam.setAdCode(adPr); } if (StringUtils.isBlank(typeParam.getpType())) { for (BisInspEnum inspEnum : BisInspEnum.values()) { if (typeParam.getType().equals(inspEnum.getKey())) { typeParam.setpType(inspEnum.getValue()); break; } } } if (StringUtils.isBlank(typeParam.getTabType())) { typeParam.setTabType(CommonLabel.TAB_TYPE); } String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); typeParam.setNowTime(nowTime); BisInspObjStrategy strategy = factory.createStrategy(typeParam.getpType()); typeParam = setParam(typeParam, request); PageInfo pageInfo = strategy.findObjPageByType(typeParam, response); return buildSuccessResponse(pageInfo); } @Authority @ApiOperation(value = "【获取全部】根据记录人员id获取需要督查水库(type=rsvr),农水(type=vill),水毁(type=rect),172工程列表(type=empwt,pType=4建设,7运行),地下水(type=grw)水闸(type=waga),persId人员id,plnaId批次id") @RequestMapping(value = "/typeAll", method = RequestMethod.POST) public Object listTypeAll(@RequestBody TypeParam typeParam, HttpServletRequest request) { typeParam.setPresId(getCurrentPersId()); BisInspEnum bisInspEnum = null; for (BisInspEnum inspEnum : BisInspEnum.values()) { if (StringUtils.isBlank(typeParam.getType())) { continue; } if (typeParam.getType().equals(inspEnum.getKey())) { bisInspEnum = inspEnum; break; } } if (bisInspEnum != null) { if (StringUtils.isBlank(typeParam.getpType())) { typeParam.setpType(bisInspEnum.getValue()); } BisInspObjStrategy strategy = factory.createStrategy(bisInspEnum.getValue()); if (strategy == null) { throw new CheckException("查询加载异常:" + bisInspEnum.getValue()); } typeParam = setParam(typeParam, request); Object result = strategy.findObjListByType(typeParam); return buildSuccessResponse(result); } return buildFailResponse("无重要列表信息!!"); } private TypeParam setParam(TypeParam typeParam, HttpServletRequest request) { if (StringUtils.isBlank(typeParam.getTabType())) { typeParam.setTabType(CommonLabel.TAB_TYPE); String source = request.getHeader("source"); if (StringUtils.isNotBlank(source)) { typeParam.setTabType("0"); } } String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); typeParam.setNowTime(nowTime); typeParam.setOrgId(getCurrentOrgId()); typeParam.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); typeParam.setPresId(getCurrentPersId()); typeParam.setInIdsSql(SqlUtils.getinIdsSql(typeParam.getPresId(), typeParam.getProvince())); if (StringUtils.isNotBlank(typeParam.getRsName())) { typeParam.setName(typeParam.getRsName()); } if (StringUtils.isNotBlank(typeParam.getAdCode())) { typeParam.setAdCode(typeParam.getAdCode().replace("00", "")); } if (StringUtils.isNotBlank(typeParam.getOrderBy()) && typeParam.getOrderBy().contains("SCHINESE_PINYIN_M")) { if("mysql".equals(sqlDialect)){ typeParam.setOrderBy("CONVERT( nm USING gbk ) COLLATE gbk_chinese_ci ASC"); }else{ typeParam.setOrderBy("nlssort(nm,'NLS_SORT=SCHINESE_PINYIN_M')"); } } if (StringUtils.isNotBlank(typeParam.getOrderBy()) && typeParam.getOrderBy().contains("#")) { if (typeParam.getOrderBy().startsWith("#")) { if("mysql".equals(sqlDialect)){ typeParam.setOrderBy("CONVERT( nm USING gbk ) COLLATE gbk_chinese_ci ASC"); }else{ typeParam.setOrderBy("nlssort(nm,'NLS_SORT=SCHINESE_PINYIN_M')"); } } else { String orderBy = typeParam.getOrderBy().replace("#", " "); typeParam.setOrderBy(orderBy); if("mysql".equals(sqlDialect) && typeParam.getOrderBy().contains("nlssort")){ typeParam.setOrderBy(null); } } } return typeParam; } }