|
@@ -0,0 +1,385 @@
|
|
|
+package com.minpay.shouhuo.productaction;
|
|
|
+
|
|
|
+import com.min.util.CommonUtil;
|
|
|
+import com.minpay.common.bean.User;
|
|
|
+import com.minpay.common.exception.BusinessCodeException;
|
|
|
+import com.minpay.common.format.IFormatService;
|
|
|
+import com.minpay.common.service.ILogService;
|
|
|
+import com.minpay.common.service.IPublicService;
|
|
|
+import com.minpay.common.util.DateUtil;
|
|
|
+import com.minpay.db.table.mapper.VmProductInfMapper;
|
|
|
+import com.minpay.db.table.model.VmProductInf;
|
|
|
+import com.minpay.db.table.own.mapper.ProductManageMapper;
|
|
|
+import com.startup.minpay.frame.business.IMINAction;
|
|
|
+import com.startup.minpay.frame.business.res.MINActionResult;
|
|
|
+import com.startup.minpay.frame.constant.IMINBusinessConstant;
|
|
|
+import com.startup.minpay.frame.constant.IMINTransactionEnum;
|
|
|
+import com.startup.minpay.frame.data.format.MINCopyFormat;
|
|
|
+import com.startup.minpay.frame.exception.MINBusinessException;
|
|
|
+import com.startup.minpay.frame.jdbc.MINRowBounds;
|
|
|
+import com.startup.minpay.frame.service.base.IMINDataBaseService;
|
|
|
+import com.startup.minpay.frame.service.base.Service;
|
|
|
+import com.startup.minpay.frame.session.MINSession;
|
|
|
+import com.startup.minpay.frame.target.MINAction;
|
|
|
+import com.startup.minpay.frame.target.MINComponent;
|
|
|
+import com.startup.minpay.frame.target.MINParam;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商品管理
|
|
|
+ * @author pangjl
|
|
|
+ * 20190325
|
|
|
+ */
|
|
|
+@MINComponent
|
|
|
+public class ProductManageAction implements IMINAction {
|
|
|
+
|
|
|
+ /**查看商品*/
|
|
|
+ public final static String QUERY_PRODUCT_INF = "queryProductInf";
|
|
|
+ /**查看正常状态商品*/
|
|
|
+ public final static String QUERY_PRODUCTZ = "queryProductz";
|
|
|
+ /**查看商品规格详情(依据商品主键)*/
|
|
|
+ public final static String QUERY_SPEC_BY_PROID = "querySpecByProid";
|
|
|
+ /** 添加商品*/
|
|
|
+ public final static String ADD_PRODUCT_INF = "addProductInf";
|
|
|
+ /** 修改商品*/
|
|
|
+ public final static String MODIFY_PRODUCT_INF = "modifyProductInf";
|
|
|
+ /** 更改商品状态*/
|
|
|
+ public final static String MODIFY_PRODUCT_STATE = "modifyProductState";
|
|
|
+ private boolean contains;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看商品
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param brandName 品牌名称
|
|
|
+ * @param model 商品型号
|
|
|
+ * @param createUser 添加人
|
|
|
+ * @param dates 添加时间
|
|
|
+ * @param page
|
|
|
+ * @param limit
|
|
|
+ * @return
|
|
|
+ * @throws MINBusinessException
|
|
|
+ */
|
|
|
+ @MINAction(value = QUERY_PRODUCT_INF)
|
|
|
+ public MINActionResult queryProductInf(
|
|
|
+ @MINParam(key = "name") String name,
|
|
|
+ @MINParam(key = "model") String model,
|
|
|
+ @MINParam(key = "dates")String dates,
|
|
|
+ @MINParam(key = "state") String state,
|
|
|
+ @MINParam(key = "brandName") String brandName,
|
|
|
+ @MINParam(key = "categoryId") String categoryId,
|
|
|
+ @MINParam(key = "categoryName") String categoryName,
|
|
|
+ @MINParam(key = "createUser") String createUser,
|
|
|
+ @MINParam(key = "page", defaultValue = "1") int page,
|
|
|
+ @MINParam(key = "limit", defaultValue = "3") int limit,
|
|
|
+ MINSession session) throws MINBusinessException {
|
|
|
+
|
|
|
+ MINActionResult res = new MINActionResult();
|
|
|
+ User user = session.getUser();
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ //按商品名称,商品品牌进行模糊查询
|
|
|
+ map.put("name", name); //商品名称
|
|
|
+ map.put("state", state);//状态
|
|
|
+ map.put("model",model);
|
|
|
+ map.put("dates",dates);
|
|
|
+ map.put("brandName",brandName);
|
|
|
+ map.put("createUser",createUser);
|
|
|
+ map.put("channel", user.getChannel());//渠道号
|
|
|
+ map.put("category", categoryId);//分类
|
|
|
+ //验证操作员权限
|
|
|
+// if("00".equals(user.getIdentity())){
|
|
|
+ map.put("userId",user.getId());
|
|
|
+// map.put("roId","10000001");
|
|
|
+// }
|
|
|
+/* if("10000002".equals(user.getRoleId())){
|
|
|
+ map.put("userId",user.getId());
|
|
|
+ }*/
|
|
|
+ //分页
|
|
|
+ MINRowBounds rows = new MINRowBounds(page, limit);
|
|
|
+ //执行查询
|
|
|
+ List<Map<String, String>> list = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ProductManageMapper.class)
|
|
|
+ .queryProductInf(map, rows);
|
|
|
+ //格式化时间和状态
|
|
|
+ list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime","modifyTime");
|
|
|
+ list = new MINCopyFormat("{history:'historyDesc',state:'stateDesc',source:'sourceDesc'}").format(list);
|
|
|
+ list = Service.lookup(IFormatService.class).formatEnum(list,"{historyDesc:'PRODUCT_HISTORY',stateDesc:'PRODUCT_STATE',sourceDesc:'PRODUCT_SOURCE'}");
|
|
|
+ //返回数据
|
|
|
+ res.set(IMINBusinessConstant.F_PAGING_LAY, list);
|
|
|
+ res.set(IMINBusinessConstant.F_PAGING_COUNT,rows.getMaxRows());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加商品
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param categoryId 分类id
|
|
|
+ * @param brandId 品牌id
|
|
|
+ * @param number 商品数量
|
|
|
+ * @param describe 商品描述
|
|
|
+ * @param piclist 多图片
|
|
|
+ * @param sort 排序
|
|
|
+ * @param fmpic 封面图片
|
|
|
+ * @param unit 商品单位
|
|
|
+ * @param masterMap 商品主图
|
|
|
+ * @param session
|
|
|
+ * @return
|
|
|
+ * @throws MINBusinessException
|
|
|
+ */
|
|
|
+ @MINAction(value = ADD_PRODUCT_INF,transaction = IMINTransactionEnum.CMT)
|
|
|
+ public MINActionResult addProductInf(
|
|
|
+ @MINParam(key = "name") String name,
|
|
|
+ @MINParam(key = "categoryId") String categoryId,
|
|
|
+ @MINParam(key = "brandId") String brandId,
|
|
|
+ @MINParam(key = "number") String number,
|
|
|
+ @MINParam(key = "describe") String describe,
|
|
|
+ @MINParam(key = "piclist") String piclist,
|
|
|
+ @MINParam(key = "sort") String sort,
|
|
|
+ @MINParam(key = "address") String address,
|
|
|
+ @MINParam(key = "fmpic") String fmpic,
|
|
|
+ @MINParam(key = "unit") String unit,
|
|
|
+ @MINParam(key = "masterMap") String masterMap,
|
|
|
+ @MINParam(key = "specIds") String specIds,
|
|
|
+ MINSession session) throws MINBusinessException {
|
|
|
+
|
|
|
+ MINActionResult res = new MINActionResult();
|
|
|
+ //获取当前时间
|
|
|
+ String nowTime = DateUtil.getCurrentDateTimeString();
|
|
|
+ // 获取操作员信息
|
|
|
+ User user = session.getUser();
|
|
|
+ // 获取商品主键
|
|
|
+ String id = Service.lookup(IPublicService.class).getSequence("VM_PRODUCT_ID");
|
|
|
+ VmProductInf pro = new VmProductInf();
|
|
|
+ pro.setId(id); // 商品id
|
|
|
+ pro.setName(name); // 商品名称
|
|
|
+ pro.setDescribe(describe); // 商品描述
|
|
|
+ pro.setCategoryId(categoryId); // 分类id
|
|
|
+ pro.setFmpic(fmpic); // 封面图片
|
|
|
+ pro.setState("0"); // 默认状态正常
|
|
|
+ pro.setChannel(user.getChannel()); // 渠道号
|
|
|
+ pro.setMasterMap(masterMap); //商品主图
|
|
|
+ /*String piclist2 = piclist.substring(0, piclist.length() - 1);
|
|
|
+ String imgss[] = piclist2.split(",");*/
|
|
|
+/* // 至少上传2张图片
|
|
|
+ if (imgss.length < 2) {
|
|
|
+ throw new MINBusinessException("至少上传2张图片");
|
|
|
+ }
|
|
|
+ // 最多上传3张图片
|
|
|
+ else if (imgss.length > 3) {
|
|
|
+ throw new MINBusinessException("至多上传3张图片");
|
|
|
+ }*/
|
|
|
+ pro.setPiclist(piclist); // 多图片
|
|
|
+ pro.setCreateUser(user.getId()); // 创建人
|
|
|
+ pro.setCreateTime(nowTime); // 创建时间
|
|
|
+ pro.setModifyUser(user.getId()); //修改人
|
|
|
+ pro.setModifyTime(nowTime); //修改时间
|
|
|
+ // 新增商品信息,执行插入数据x
|
|
|
+ Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(VmProductInfMapper.class)
|
|
|
+ .insertSelective(pro);
|
|
|
+ // 记录操作日志
|
|
|
+ String logInfo = "操作员:" + user.getName() + "添加商品,商品编号:" + id;
|
|
|
+ Service.lookup(ILogService.class).logging(session, logInfo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改商品
|
|
|
+ * @param id 商品编号
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param categoryId 分类id
|
|
|
+ * @param brandId 品牌id
|
|
|
+ * @param number 商品数量
|
|
|
+ * @param describe 商品描述
|
|
|
+ * @param piclist 多图片
|
|
|
+ * @param sort 排序
|
|
|
+ * @param fmpic 封面图片
|
|
|
+ * @param masterMap 商品主图
|
|
|
+ * @param session
|
|
|
+ * @return
|
|
|
+ * @throws MINBusinessException
|
|
|
+ */
|
|
|
+ @MINAction(value = MODIFY_PRODUCT_INF,transaction = IMINTransactionEnum.CMT)
|
|
|
+ public MINActionResult modifyProductInf(
|
|
|
+ @MINParam(key = "id") String id,
|
|
|
+ @MINParam(key = "name") String name,
|
|
|
+ @MINParam(key = "categoryId") String categoryId,
|
|
|
+ @MINParam(key = "brandId") String brandId,
|
|
|
+ @MINParam(key = "number") String number,
|
|
|
+ @MINParam(key = "describe") String describe,
|
|
|
+ @MINParam(key = "piclist") String piclist,
|
|
|
+ @MINParam(key = "sort") String sort,
|
|
|
+ @MINParam(key = "fmpic") String fmpic,
|
|
|
+ @MINParam(key = "masterMap") String masterMap,
|
|
|
+ @MINParam(key = "specIds") String specIds,
|
|
|
+ MINSession session) throws MINBusinessException {
|
|
|
+
|
|
|
+ MINActionResult res = new MINActionResult();
|
|
|
+ //获取当前时间
|
|
|
+ String nowTime = DateUtil.getCurrentDateTimeString();
|
|
|
+ // 获取操作员信息
|
|
|
+ User user = session.getUser();
|
|
|
+ // 获取要修改的商品信息
|
|
|
+ VmProductInf pro = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(VmProductInfMapper.class)
|
|
|
+ .selectByPrimaryKey(id);
|
|
|
+ if(pro == null) {
|
|
|
+ throw new BusinessCodeException("JINM0121");//商品信息异常
|
|
|
+ }
|
|
|
+ pro.setId(id); // 商品id
|
|
|
+ if(!CommonUtil.isEmpty(name)){
|
|
|
+ pro.setName(name); // 商品名称
|
|
|
+ }
|
|
|
+ if(!CommonUtil.isEmpty(describe)){
|
|
|
+ pro.setDescribe(describe); // 商品描述
|
|
|
+ }
|
|
|
+ if(!CommonUtil.isEmpty(categoryId)){
|
|
|
+ pro.setCategoryId(categoryId); // 分类id
|
|
|
+ }
|
|
|
+ if(!CommonUtil.isEmpty(fmpic)){
|
|
|
+ pro.setFmpic(fmpic); // 封面图片
|
|
|
+ }
|
|
|
+ if(!CommonUtil.isEmpty(masterMap)){
|
|
|
+ pro.setMasterMap(masterMap); //商品主图
|
|
|
+ }
|
|
|
+ /*String piclist2 = piclist.substring(0, piclist.length() - 1);
|
|
|
+ String imgss[] = piclist2.split(",");*/
|
|
|
+ /*// 至少上传2张图片
|
|
|
+ if (imgss.length < 2) {
|
|
|
+ throw new MINBusinessException("至少上传2张图片");
|
|
|
+ }
|
|
|
+ // 最多上传3张图片
|
|
|
+ else if (imgss.length > 3) {
|
|
|
+ throw new MINBusinessException("至多上传3张图片");
|
|
|
+ }
|
|
|
+ if(!CommonUtil.isEmpty(piclist)){
|
|
|
+ pro.setPiclist(piclist); // 多图片
|
|
|
+ }*/
|
|
|
+ pro.setModifyUser(user.getId()); //修改人
|
|
|
+ pro.setModifyTime(nowTime); //修改时间
|
|
|
+ // 修改商品信息,执行修改
|
|
|
+ Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(VmProductInfMapper.class)
|
|
|
+ .updateByPrimaryKeySelective(pro);
|
|
|
+ // 记录操作日志
|
|
|
+ String logInfo = "操作员:" + user.getName() + "修改商品,商品编号:" + id;
|
|
|
+ Service.lookup(ILogService.class).logging(session, logInfo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更改商品状态
|
|
|
+ * @param proId 商品Id
|
|
|
+ * @param proState 商品状态
|
|
|
+ * @param xiaoliang 商品销量
|
|
|
+ * @param session
|
|
|
+ * @return
|
|
|
+ * @throws MINBusinessException
|
|
|
+ */
|
|
|
+ @MINAction(value = MODIFY_PRODUCT_STATE,transaction = IMINTransactionEnum.CMT)
|
|
|
+ public MINActionResult modifyProductState(
|
|
|
+ @MINParam(key = "proId") String proId,
|
|
|
+ @MINParam(key = "proState") String proState,
|
|
|
+ @MINParam(key = "xiaoliang") String xiaoliang,
|
|
|
+ MINSession session) throws MINBusinessException {
|
|
|
+ MINActionResult res = new MINActionResult();
|
|
|
+ String nowTime = DateUtil.getCurrentDateTimeString();
|
|
|
+ // 获取操作员信息
|
|
|
+ User user = session.getUser();
|
|
|
+ // 获取渠道
|
|
|
+ String channel = user.getChannel();
|
|
|
+ VmProductInf proInf = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(VmProductInfMapper.class).selectByPrimaryKey(proId);
|
|
|
+ if(proInf == null ){
|
|
|
+ throw new BusinessCodeException("JINM0123");//商品信息异常
|
|
|
+ }
|
|
|
+ proInf.setId(proId); // 商品id
|
|
|
+ //000-恢复,111-停售
|
|
|
+ if("000".equals(proState)){
|
|
|
+ proInf.setState("0"); // 商品状态:正常
|
|
|
+ proState = "0";
|
|
|
+ }else if("111".equals(proState)){
|
|
|
+ proInf.setState("1");//商品状态:停售
|
|
|
+ proState = "1";
|
|
|
+ }else if("222".equals(proState)){
|
|
|
+ proInf.setState("2"); //商品状态:删除
|
|
|
+ proState = "2";
|
|
|
+ }
|
|
|
+
|
|
|
+ proInf.setModifyUser(user.getId()); // 修改人
|
|
|
+ proInf.setModifyTime(nowTime); // 修改时间
|
|
|
+ // 执行修改
|
|
|
+ Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(VmProductInfMapper.class)
|
|
|
+ .updateByPrimaryKeySelective(proInf);
|
|
|
+ // 记录操作日志
|
|
|
+ String logInfo = "操作员:" + user.getName() + "更改商品状态,商品编号:" + proId+",商品状态:"+proState;
|
|
|
+ Service.lookup(ILogService.class).logging(session, logInfo);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查看商品
|
|
|
+ * @param name 商品名称
|
|
|
+ * @param brandName 品牌名称
|
|
|
+ * @param model 商品型号
|
|
|
+ * @param createUser 添加人
|
|
|
+ * @param dates 添加时间
|
|
|
+ * @param page
|
|
|
+ * @param limit
|
|
|
+ * @return
|
|
|
+ * @throws MINBusinessException
|
|
|
+ */
|
|
|
+ @MINAction(value = QUERY_PRODUCTZ)
|
|
|
+ public MINActionResult queryProductz(
|
|
|
+ @MINParam(key = "name") String name,
|
|
|
+ @MINParam(key = "model") String model,
|
|
|
+ @MINParam(key = "dates")String dates,
|
|
|
+ @MINParam(key = "state") String state,
|
|
|
+ @MINParam(key = "brandName") String brandName,
|
|
|
+ @MINParam(key = "categoryId") String categoryId,
|
|
|
+ @MINParam(key = "createUser") String createUser,
|
|
|
+ @MINParam(key = "page", defaultValue = "1") int page,
|
|
|
+ @MINParam(key = "limit", defaultValue = "3") int limit,
|
|
|
+ MINSession session) throws MINBusinessException {
|
|
|
+
|
|
|
+ MINActionResult res = new MINActionResult();
|
|
|
+ User user = session.getUser();
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
+ //按商品名称,商品品牌进行模糊查询
|
|
|
+ map.put("name", name); //商品名称
|
|
|
+ map.put("state", state);//状态
|
|
|
+ map.put("model",model);
|
|
|
+ map.put("dates",dates);
|
|
|
+ map.put("brandName",brandName);
|
|
|
+ map.put("createUser",createUser);
|
|
|
+ map.put("channel", user.getChannel());//渠道号
|
|
|
+ map.put("category", categoryId);//分类
|
|
|
+ //验证操作员权限
|
|
|
+// if("00".equals(user.getIdentity())){
|
|
|
+// map.put("userId",user.getId());
|
|
|
+// }
|
|
|
+/* if("10000002".equals(user.getRoleId())){
|
|
|
+ map.put("userId",user.getId());
|
|
|
+ }*/
|
|
|
+ //分页
|
|
|
+ MINRowBounds rows = new MINRowBounds(page, limit);
|
|
|
+ //执行查询
|
|
|
+ List<Map<String, String>> list = Service.lookup(IMINDataBaseService.class)
|
|
|
+ .getMybatisMapper(ProductManageMapper.class)
|
|
|
+ .queryProductz(map, rows);
|
|
|
+ //格式化时间和状态
|
|
|
+ list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime","modifyTime");
|
|
|
+ list = new MINCopyFormat("{history:'historyDesc',state:'stateDesc',source:'sourceDesc'}").format(list);
|
|
|
+ list = Service.lookup(IFormatService.class).formatEnum(list,"{historyDesc:'PRODUCT_HISTORY',stateDesc:'PRODUCT_STATE',sourceDesc:'PRODUCT_SOURCE'}");
|
|
|
+ //返回数据
|
|
|
+ res.set(IMINBusinessConstant.F_PAGING_LAY, list);
|
|
|
+ res.set(IMINBusinessConstant.F_PAGING_COUNT,rows.getMaxRows());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|