|
|
@@ -1,7 +1,39 @@
|
|
|
package com.sckw.system.service;
|
|
|
|
|
|
+import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
+import com.sckw.core.exception.SystemException;
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
+import com.sckw.core.model.constant.NumberConstant;
|
|
|
+import com.sckw.core.model.enums.EntTypeEnum;
|
|
|
+import com.sckw.core.model.enums.SystemTypeEnum;
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
+import com.sckw.core.utils.NumberUtils;
|
|
|
+import com.sckw.core.utils.StringUtils;
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
+import com.sckw.core.web.context.LoginUserHolder;
|
|
|
+import com.sckw.core.web.response.HttpResult;
|
|
|
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
+import com.sckw.system.api.model.dto.res.SysDictResDto;
|
|
|
+import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
+import com.sckw.system.dao.KwsEntSpecialDao;
|
|
|
+import com.sckw.system.dao.KwsEnterpriseDao;
|
|
|
+import com.sckw.system.dao.KwsSpecialDao;
|
|
|
+import com.sckw.system.dao.KwsUserDao;
|
|
|
+import com.sckw.system.model.KwsEntSpecial;
|
|
|
+import com.sckw.system.model.KwsEnterprise;
|
|
|
+import com.sckw.system.model.KwsSpecial;
|
|
|
+import com.sckw.system.model.KwsUser;
|
|
|
+import com.sckw.system.model.vo.req.KwsSpecialAddReqVo;
|
|
|
+import com.sckw.system.model.vo.req.KwsSpecialUpdateReqVo;
|
|
|
+import com.sckw.system.model.vo.res.KwsSpecialResVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* @desc 专场
|
|
|
* @author zk
|
|
|
@@ -10,4 +42,221 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class KwsSpecialService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ KwsSpecialDao kwsSpecialDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsEntSpecialDao kwsEntSpecialDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsUserDao kwsUserDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsEnterpriseDao kwsEnterpriseDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param key 主键id
|
|
|
+ * @desc 根据主键查询
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public KwsSpecial selectByKey(Long key) {
|
|
|
+ return kwsSpecialDao.selectById(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param id 车辆档案ID
|
|
|
+ * @desc 专场详情
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public KwsSpecialResVo detail(Long id){
|
|
|
+ //车辆信息
|
|
|
+ KwsSpecial special = kwsSpecialDao.selectById(id);
|
|
|
+ KwsSpecialResVo specialResVo = new KwsSpecialResVo();
|
|
|
+ BeanUtils.copyPropertiesValue(special, specialResVo);
|
|
|
+
|
|
|
+ //数据组装
|
|
|
+ if (special != null) {
|
|
|
+ //客户经理
|
|
|
+ KwsUser manager = kwsUserDao.selectByKey(special.getManager());
|
|
|
+ //创建人
|
|
|
+ KwsUser createBy = kwsUserDao.selectByKey(special.getCreateBy());
|
|
|
+ //专场企业
|
|
|
+ KwsEnterprise enterprise = kwsEnterpriseDao.selectByKey(special.getEntId());
|
|
|
+
|
|
|
+ specialResVo.setManagerName(manager != null ? manager.getName() : null);
|
|
|
+ specialResVo.setCreateByName(createBy != null ? createBy.getName() : null);
|
|
|
+ specialResVo.setFirmName(enterprise != null ? enterprise.getFirmName() : null);
|
|
|
+ return specialResVo;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 分页参数
|
|
|
+ * @desc 分页查询
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public List<KwsSpecialResVo> findPage(Map<String, Object> params) {
|
|
|
+ /*查询分页数据**/
|
|
|
+ List<KwsSpecialResVo> specials = kwsSpecialDao.findPage(params);
|
|
|
+ return specials;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 查询参数
|
|
|
+ * @desc 查询
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public List<KwsSpecial> findList(Map<String, Object> params) {
|
|
|
+ return kwsSpecialDao.findList(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 新增专场
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public HttpResult add(KwsSpecialAddReqVo params) {
|
|
|
+ /*校验*/
|
|
|
+ List<KwsSpecial> specials = kwsSpecialDao.findList(new HashMap<>(){{put("name", params.getName());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(specials)) {
|
|
|
+ return HttpResult.error("专场名称已存在!");
|
|
|
+ }
|
|
|
+ specials = kwsSpecialDao.findList(new HashMap<>(){{put("code", params.getCode());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(specials)) {
|
|
|
+ return HttpResult.error("专场编号已存在!");
|
|
|
+ }
|
|
|
+ specials = kwsSpecialDao.findList(new HashMap<>(){{put("entId", params.getEntId());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(specials)) {
|
|
|
+ return HttpResult.error("企业已属专于专场主企业!");
|
|
|
+ }
|
|
|
+ List<KwsEntSpecial> entSpecials = kwsEntSpecialDao.findList(new HashMap<>(){{put("entId", params.getEntId());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(entSpecials)) {
|
|
|
+ return HttpResult.error("企业已属于专场企业!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*数据更新*/
|
|
|
+ KwsSpecial special = new KwsSpecial();
|
|
|
+ BeanUtils.copyProperties(params, special);
|
|
|
+ int count = kwsSpecialDao.insert(special);
|
|
|
+ return count > 0 ? HttpResult.ok("专场信息新增成功!") : HttpResult.error("专场信息新增失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 参数
|
|
|
+ * @desc 修改专场
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public HttpResult update(KwsSpecialUpdateReqVo params) {
|
|
|
+ /*校验*/
|
|
|
+ KwsSpecial special = kwsSpecialDao.selectById(params.getId());
|
|
|
+ if (special == null) {
|
|
|
+ return HttpResult.error("专场信息不存在!");
|
|
|
+ }
|
|
|
+ List<KwsSpecial> specials = kwsSpecialDao.findList(new HashMap<>(){{put("name", params.getName());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(specials)) {
|
|
|
+ KwsSpecial special1 = specials.get(NumberConstant.ZERO);
|
|
|
+ if (!special1.getId().equals(special.getId())) {
|
|
|
+ return HttpResult.error("专场名称已存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ specials = kwsSpecialDao.findList(new HashMap<>(){{put("code", params.getCode());}});
|
|
|
+ if (CollectionUtils.isEmpty(specials)) {
|
|
|
+ KwsSpecial special1 = specials.get(NumberConstant.ZERO);
|
|
|
+ if (!special1.getId().equals(special.getId())) {
|
|
|
+ return HttpResult.error("专场编号已存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ specials = kwsSpecialDao.findList(new HashMap<>(){{put("entId", params.getEntId());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(specials)) {
|
|
|
+ KwsSpecial special1 = specials.get(NumberConstant.ZERO);
|
|
|
+ if (!special1.getId().equals(special.getId())) {
|
|
|
+ return HttpResult.error("企业已属专于专场主企业!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<KwsEntSpecial> entSpecials = kwsEntSpecialDao.findList(new HashMap<>(){{put("entId", params.getEntId());}});
|
|
|
+ if (CollectionUtils.isNotEmpty(entSpecials)) {
|
|
|
+ return HttpResult.error("企业已属于专场企业!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*数据更新*/
|
|
|
+ BeanUtils.copyProperties(params, special);
|
|
|
+ int count = kwsSpecialDao.updateById(special);
|
|
|
+ return count > 0 ? HttpResult.ok("专场信息修改成功!") : HttpResult.error("专场信息修改失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ids {ids:主键ID(多个以逗号隔开)}
|
|
|
+ * @desc 删除
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public HttpResult del(String ids) {
|
|
|
+ /*数据校验**/
|
|
|
+ if (StringUtils.isBlank(ids)) {
|
|
|
+ return HttpResult.error("请选择要删除的数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /*数据组装**/
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
+ for (String id : idArray) {
|
|
|
+ KwsSpecial special = kwsSpecialDao.selectById(id);
|
|
|
+ if (special != null) {
|
|
|
+ special.setDelFlag(Global.YES);
|
|
|
+ if (kwsSpecialDao.updateById(special) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return HttpResult.error("选择删除的数据已不存在!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return HttpResult.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params {}
|
|
|
+ * @desc 加入专场
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/12/13
|
|
|
+ **/
|
|
|
+ public HttpResult joinSpecial(HashMap<String, Object> params) {
|
|
|
+ /*校验*/
|
|
|
+ if (StringUtils.isBlank(params.get("id")) || StringUtils.isBlank(params.get("entIds"))) {
|
|
|
+ return HttpResult.error("参数不能为空!");
|
|
|
+ }
|
|
|
+ Long id = NumberUtils.parseLong(params.get("id"));
|
|
|
+ String entIds = StringUtils.objectStr(params.get("entIds"));
|
|
|
+ String[] idArray = entIds.split(",");
|
|
|
+ for (String entId : idArray) {
|
|
|
+ List<KwsSpecial> specials = kwsSpecialDao.findList(new HashMap<>(){{put("entId", entId);}});
|
|
|
+ if (CollectionUtils.isNotEmpty(specials)) {
|
|
|
+ return HttpResult.error("企业已属专于专场主企业!");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<KwsEntSpecial> entSpecials = kwsEntSpecialDao.findList(new HashMap<>(){{put("entId", entId);}});
|
|
|
+ if (CollectionUtils.isNotEmpty(entSpecials)) {
|
|
|
+ KwsEnterprise enterprise = kwsEnterpriseDao.selectByKey(Long.parseLong(entId));
|
|
|
+ if (enterprise != null) {
|
|
|
+ return HttpResult.error(enterprise.getFirmName() + "已属于专场企业!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*数据组装存储*/
|
|
|
+ for (String entId : idArray) {
|
|
|
+ KwsEntSpecial entSpecial = new KwsEntSpecial();
|
|
|
+ entSpecial.setSpecialId(id);
|
|
|
+ entSpecial.setEntId(Long.parseLong(entId));
|
|
|
+ kwsEntSpecialDao.insert(entSpecial);
|
|
|
+ }
|
|
|
+
|
|
|
+ return HttpResult.ok("加入专场成功!");
|
|
|
+ }
|
|
|
}
|